<template>
  <template v-for="subItem in menuList" :key="subItem.path">
    <el-sub-menu v-if="subItem.children?.length" :index="subItem.path">
      <template #title>
        <!-- <el-icon>
          <component :is="subItem.meta.icon"></component>
        </el-icon> -->
        <i :class="subItem.meta.icon" class="iconfont2"> </i>
        <span class="sle">{{ subItem.meta.title }}</span>
      </template>
      <SubMenu :menu-list="subItem.children" />
    </el-sub-menu>
    <el-menu-item v-else :index="subItem.path" @click="handleClickMenu(subItem)">
      <i :class="subItem.meta.icon" class="iconfont2"> </i>
      <template #title>
        <span class="sle">{{ subItem.meta.title }}</span>
      </template>
    </el-menu-item>
  </template>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { useFondsStore } from "@/stores/modules/fonds";
import useCurrentInstance from "@/utils/useCurrentInstance";
import localCache from "@/utils/cache";

defineProps<{ menuList: Menu.MenuOptions[] }>();

const { proxy } = useCurrentInstance();
// pinia
const fondsStore = useFondsStore();
// router
const router = useRouter();
const handleClickMenu = (subItem: any) => {
  if (subItem.meta.isLink) return window.open(subItem.meta.isLink, "_blank");

  if (subItem.Type?.includes("FMT")) {
    fondsStore.SetFondsObj(subItem);
    localCache.setCache("fondObj", subItem, false);
    // 获取全宗路由下的子级
    proxy.$vueAxios
      .post(
        "Master_Base_FormModel_Table/GetConditional",
        {
          order: "FMT_Type ASC",
          dtoList: [
            {
              fieldName: "FM_ID",
              fieldValue: subItem.FM_ID
            }
          ]
        },
        { noLoading: true }
      )
      .then((res: any) => {
        console.log("%%%%%%%%%%%%%%%%", res);
        const childrenFmtId2 = res.List.filter((v: any) => v.FMT_Parent_ID === subItem.FMT_ID).map((v: any) => v.FMT_ID);
        router.push({
          // path: subItem.path,
          name: "MainModal",
          params: { id: subItem.ID },
          query: {
            fmid: subItem.FM_ID,
            fmtid: subItem.FMT_ID,
            status: subItem.Archive_Status,
            childrenFmtId: childrenFmtId2,
            fatherObj: undefined,
            fatherFmtId: undefined,
            fondsId: subItem.Fonds_ID
          }
        });
      });
  } else {
    router.push(subItem.path);
  }
};
</script>

<style lang="scss">
.iconfont2 {
  width: 24px;
  font-size: 14px;
  text-align: center;
}
.el-sub-menu .el-sub-menu__title:hover {
  color: var(--el-menu-hover-text-color) !important;
  background-color: transparent !important;
}
.el-menu--collapse {
  .is-active {
    .el-sub-menu__title {
      color: #ffffff !important;
      background-color: var(--el-color-primary) !important;
    }
  }
}
.el-menu-item {
  &:hover {
    color: var(--el-menu-hover-text-color);
  }
  &.is-active {
    color: var(--el-menu-active-color) !important;
    background-color: var(--el-menu-active-bg-color) !important;
    &::before {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 4px;
      content: "";
      background-color: var(--el-color-primary);
    }
  }
}
.vertical,
.classic,
.transverse {
  .el-menu-item {
    &.is-active {
      &::before {
        left: 0;
      }
    }
  }
}
.columns {
  .el-menu-item {
    &.is-active {
      &::before {
        right: 0;
      }
    }
  }
}
.classic,
.transverse {
  #driver-highlighted-element-stage {
    background-color: #606266 !important;
  }
}
</style>
